
struct PARAMS_IN
{
    float4 wPos : SV_Position;
    [[vk::location(0)]] float2 vTex : MY_TEX;
};

struct PARAMS_OUT
{
    float4 k_color : SV_Target;
};

cbuffer BackInfo : register(b0, space0)
{
    float4 g_param0 : packoffset(c0);
    float4 g_param1 : packoffset(c1);
}

#define tex2DLevelOffset(s, t, l, f)        s.SampleLevel(s##Sampler, t, l, f)

SamplerState g_samBack : register(s0, space1);
Texture2D g_texBack : register(t0, space2);
Texture3D g_tex3d : register(t1, space2);

void main( PARAMS_IN pIn, out PARAMS_OUT pOut )
{
    uint2 colrow = uint2(pIn.wPos.xy);

    // 2d texture background
    float4 clr = //g_texBack.Load(uint3(colrow, 0)); 
                 //g_texBack.Sample(g_samBack, pIn.vTex);
                 g_texBack.SampleLevel(g_samBack, pIn.vTex, 0.0, int2(-7, 0));

#if 1
    clr = 0;

    const int2 Offsets[9] =
	{
		int2(-1, -1),
		int2( 0, -1),
		int2( 1, -1),
		int2(-1,  0),
		int2( 0,  0),
		int2( 1,  0),
		int2(-1,  1),
		int2( 0,  1),
		int2( 1,  1),
	};

    [unroll] for( uint i = 0; i < 9; i++ )
    {
        clr += g_texBack.SampleLevel(g_samBack, pIn.vTex, 0.0, Offsets[i]);
    }

    clr /= 9;
#endif

    clr *= g_param0;

    // 3d texture test
    float3 tuv;
    tuv.xy = pIn.vTex * 20;
    tuv.z = g_param1.x;

    colrow /= 4;
    float4 clr2 = g_tex3d.Load( uint4(colrow % uint2(32,32), uint(g_param1.x * 31), 0) );
                 //g_tex3d.SampleLevel(g_samBack, tuv, 0);
    clr = lerp(clr, clr2, 0.3);

    // out
    pOut.k_color = clr;
}

